define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function() {
		this.callParent();
		this.showView = justep.Bind.observable(false); // 默认不显示视图
		this.menuDrop = justep.Bind.observable('2'); // 下拉菜单序号
		this.groupName = justep.Bind.observable(''); // 公众号参数分组名称
	};

	Model.prototype.showPageClick = function(event) {
		var url = event.source.$domNode.attr('url') + '?groupName=' + this.groupName.get();
		var index = $(event.source.$domNode).index();
		this.menuDrop.set(index + 1);
		this.showView.set(true);
		this.comp('pageContainer').load(require.toUrl(url));
	};

	Model.prototype.mainPageClick = function(event) {
		this.menuDrop.set(0);
		this.showView.set(false);
	};

	Model.prototype.backCheckBtnClick = function(event) {
		this.showView.set(false);
	};

	Model.prototype.button2Click = function(event) {
		// 选择小程序参数分组
		var appid = event.bindingContext.$object.val('fvalue');
		if (!appid || appid.length == 0) {
			justep.Util.hint("当前选择小程序appid值未设置，请先配置参数");
			return;
		} else {
			this.groupName.set(event.bindingContext.$object.val('fgroup'));
			this.showView.set(true);
			this.comp('pageContainer').load(require.toUrl('./xcxNearBy.w?groupName=' + this.groupName.get()));
		}

	};

	Model.prototype.groupsCustomerRefresh = function(event){
		var group = event.source;
		var append = event.options && event.options.append;
		var params = {
			"key" : "com.qq.weixin.miniapp.appID"
		};
		$.ajax({
			type : "GET",
			url : require.toUrl("/config/config/groups"),
			dataType : "json",
			async : false,// 使用同步方式，目前data组件有同步依赖
			cache : false,
			data : params,
			success : function(res) {
				group.loadData(res);
				group.loadData(res,append);
				group.doRefreshAfter(true, event.options);
			}
		});
	}

	return Model;
});